import Cookies from 'js-cookie'

const TokenKey = 'weiSheQU-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token, { expires: 6000 })
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

/**
 * @author gaogm
 * @param {*} key cookie key
 * @default key = TokenKey
 */
export function getTokenByKey(key = TokenKey) {
  return Cookies.get(key)
}

/**
 * @author gaogm
 * @param {*} key cookie key, default key = TokenKey
 * @param {*} data cookie value
 * @param {*} options example: { expires: 6000 }
 */
export function setTokenByKey(key = TokenKey, data, options) {
  return Cookies.set(key, data, options)
}
export function newSetTokenByKey(key = TokenKey, data, options) {
  return Cookies.set(key, data, { expires: 1 / 24 * options })
}
/**
 * @author gaogm
 * @param {*} key cookie key, default key = TokenKey
 */
export function removeTokenByKey(key = TokenKey) {
  return Cookies.remove(key)
}

const latitude = 'latitude'

export function getLat() {
  return Cookies.get(latitude)
}

export function setLat(data) {
  return Cookies.set(latitude, data)
}

export function removeLat() {
  return Cookies.remove(latitude)
}

const longitude = 'longitude'

export function getLng() {
  return Cookies.get(longitude)
}

export function setLng(data) {
  return Cookies.set(longitude, data)
}

export function removeLng() {
  return Cookies.remove(longitude)
}

export function removeAllCookies() {
  Cookies.clear()
}
